home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Revolution - Das Atari CD Magazin 1997
/
Revolution - Das Atari CD Magazin 1.iso
/
software
/
anwendng
/
qed_397
/
sourcen
/
disk.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-01-04
|
11KB
|
505 lines
#include "global.h"
#include "clipbrd.h"
#include "desktop.h"
#include "edit.h"
#include "event.h"
#include "file.h"
#include "find.h"
#include "fsel.h"
#include "icon.h"
#include "mintlib.h"
#include "projekt.h"
#include "obj.h"
#include "rsc.h"
#include "scroll.h"
#include "set.h"
#include "text.h"
#include "windows.h"
#include "disk.h"
/* exportierte Variablen ***************************************************/
WORD idisk, disk_type;
#define TEMP_LINK 10001
/* lokale Variablen ********************************************************/
LOCAL RING namen; /* Wird vor init_disk benötigt */
LOCAL BOOLEAN namen_ok = FALSE;
LOCAL WORD di_nr; /* LW-Nummer für Diskinfo */
LOCAL FSEL fsel;
/* lokale Prototypen *******************************************************/
LOCAL VOID mdiskinfo (VOID);
LOCAL VOID icon_exist (WORD icon, SET actions);
LOCAL BOOLEAN icon_test (WORD icon, WORD action);
LOCAL WORD icon_edit (WORD icon, WORD action);
LOCAL BOOLEAN icon_drag (WORD icon, WORD source);
/***************************************************************************/
LOCAL VOID icon_exist(WORD icon, SET actions)
{
setclr(actions);
setincl(actions,DO_OPEN);
setincl(actions,DO_HELP);
setincl(actions,DO_FIND);
setincl(actions,DO_INFO);
setincl(actions,DO_INIT);
}
LOCAL BOOLEAN icon_test(WORD icon, WORD action)
{
BOOLEAN erg;
switch (action)
{
case DO_INIT : erg = TRUE; break;
case DO_INFO : erg = TRUE; break;
case DO_OPEN : erg = TRUE; break;
case DO_HELP : erg = TRUE; break;
case DO_FIND : erg = TRUE; break;
default : erg = FALSE;
}
return erg;
}
LOCAL WORD icon_edit(WORD icon, WORD action)
{
WORD anz_files, i;
UBYTE **files;
PATH name, path;
switch (action)
{
case DO_INIT:
show_icon(icon);
break;
case DO_INFO:
mdiskinfo();
break;
case DO_OPEN:
name[0] = EOS;
files = select_mfile(&fsel, name, STRING(LOADFILESTR), &anz_files);
if (anz_files > 0)
{
if (files == NULL)
{
if (!global_shift && (filematch(name, "*.QPJ")))
icon = load_projekt(name, TRUE, -1, -1, NULL);
else
icon = load_edit(name, TRUE, -1, -1, NULL);
}
else
{
file_splitt(name, path, NULL);
for (i=0; i < anz_files; i++)
{
strcpy(name, path);
strcat(name, files[i]);
if (!global_shift && (filematch(name, "*.QPJ")))
icon = load_projekt(name, TRUE, -1, -1, NULL);
else
icon = load_edit(name, TRUE, -1, -1, NULL);
}
}
}
break;
case DO_HELP:
note (1, HELPDISK);
break;
case DO_FIND:
icon = crt_new_prj("",-1,-1,NULL);
if (icon<0) break;
if (do_icon(icon,DO_OPEN)<0)
{
note(1, NOWINDOW);
if (no_desktop)
{
Icon_edit(icon, DO_DESTRUCT);
break;
}
}
do_icon(icon,DO_ADD);
break;
}
return TRUE;
}
/***************************************************************************/
/* Reaktion des Verschiebens auf das DISK-Icon */
/***************************************************************************/
LOCAL BOOLEAN icon_drag (WORD icon, WORD source)
{
if (source==iclipbrd)
return (do_icon(source,DO_SAVENEW)>0);
return (do_icon(source,DO_SAVE)>0);
}
LOCAL VOID get_info(WORD objc)
{
ULONG max_len, help, free, total;
UBYTE str[20], name[15];
Busy_mouse();
if (objc)
di_nr = objc-DIA;
else if (di_nr < 0)
di_nr = get_first_drive();
get_drive_space(di_nr + 1, &total, &free);
drive_name(di_nr + 1, name);
total = total >> 10; /* kByte */
free = free >> 10; /* kByte */
ltoa(free,str,10);
fill_ptext(diskinfo, DIFREE, str);
ltoa(total,str,10);
fill_ptext(diskinfo, DITOTAL, str);
fill_ptext(diskinfo, DINAME, name);
max_len = diskinfo[DIBOX1].ob_width;
if (total > free)
help = max_len * (total - free) / total;
else
help = 1;
help = min(max_len, help);
diskinfo[DIBOX2].ob_width = (short) help;
Last_mouse();
}
LOCAL VOID mdiskinfo(VOID)
{
ULONG drv;
WORD i, btn;
DIALINFO dial;
drv = Dsetdrv(Dgetdrv());
if (drv == 0)
return;
for (i = 0; drv, i <= DIZ-DIA; drv >>= 1, i++)
if (!(drv&1))
disable_objc(diskinfo, DIA + i, TRUE);
for (i = 0; i <= DIZ - DIA; i++)
select_objc(diskinfo, DIA + i, i == di_nr);
Arrow_mouse();
open_dial(diskinfo, FALSE, NULL, &dial);
get_info(0);
dial_draw(&dial);
do
{
btn = dial_do(&dial, NULL) & 0x7FFF;
if (btn >= DIA && btn <= DIZ)
{
get_info(btn);
draw_Objc(diskinfo, DIIBOX, MAX_DEPTH);
}
}
while (btn != DIOK);
select_objc(diskinfo, DIOK, FALSE);
dial_end(&dial);
Last_mouse();
}
BOOLEAN get_qed(UBYTE *name)
{
LINEP lauf;
UBYTE *str;
FILENAME file;
if (!namen_ok) return FALSE;
lauf = FIRST(&namen);
if (IS_LAST(lauf)) return FALSE;
str = TEXT(lauf);
while (TRUE) /* letzte ist leer */
{
while (*str=='-' || *str=='"' || (*str>='0' && *str<='9'))
{
NEXT(lauf);
if (IS_LAST(lauf)) return FALSE;
str = TEXT(lauf);
}
file_name((UBYTE *)str, file, FALSE);
if (filematch(file,"*.QED") && file_exist((UBYTE *)str))
{
strcpy(name, (UBYTE *)str);
col_delete(lauf);
namen.lines--;
if (namen.lines==1)
{
kill_textring(&namen);
namen_ok = FALSE;
}
return TRUE;
}
NEXT(lauf);
if (IS_LAST(lauf)) break;
str = TEXT(lauf);
}
return FALSE;
}
BOOLEAN next_cmd(UBYTE *token, BOOLEAN destruct)
{
LINEP lauf;
if (!namen_ok) return FALSE;
lauf = FIRST(&namen);
while (lauf->info&MARKED)
{
NEXT(lauf);
if (IS_LAST(lauf)) /* letzte ist leer */
{
if (destruct)
{
kill_textring(&namen);
namen_ok = FALSE;
}
else
{
lauf = FIRST(&namen);
while (!IS_LAST(lauf))
{
lauf->info &= (~MARKED);
NEXT(lauf);
}
}
return FALSE;
}
}
lauf->info |= MARKED;
strcpy(token, (UBYTE *)TEXT(lauf));
return TRUE;
}
/* init = TRUE: immer ganz vorne einfuegen (=> andre Reihenfolge und */
/* vor Kommandozeile */
#if 0
LOCAL VOID dump_namen(VOID)
{
LINEP lauf;
Debug("namen: \n");
lauf = FIRST(&namen);
if (lauf == NULL)
Debug(" ist leer\n");
while (!IS_LAST(lauf))
{
Debug(" %s\n", TEXT(lauf));
NEXT(lauf);
}
}
#endif
VOID add_diskinfo(UBYTE *str, BOOLEAN init)
{
BOOLEAN in_quote = FALSE;
WORD i, j, len;
UBYTE zeile[256];
LINEP lauf, new,
init_namen;
if (str[0] == EOS)
return;
#if 0
Debug("add : %s\n", str);
#endif
if (!namen_ok)
{
init_textring(&namen);
namen_ok = TRUE;
}
init_namen = &namen.head;
lauf = LAST(&namen); /* letzte (leere) Zeile */
len = (short)strlen(str);
i = 0;
j = 0;
while (i <= len)
{
if (str[i] == '\'')
{
if (!in_quote || (in_quote && str[i+1] == '\''))
in_quote = TRUE;
else
in_quote = FALSE;
i++; /* ' oder " überspringen */
}
if (((str[i] == ' ') && (!in_quote))|| /* Blank als Trenner */
(i == len)) /* letztes Zeichen */
{
zeile[j] = EOS;
j = 0;
if (zeile[0] != '-' && (zeile[0] < '0' || zeile[0] > '9'))
make_normalpath(zeile, FALSE);
#if 0
Debug(" zeile: %s\n", zeile);
#endif
new = new_col_b((UBYTE *) zeile, (short) strlen(zeile));
if (init)
{
col_insert(init_namen, new);
NEXT(init_namen);
}
else
col_insert(lauf->vorg, new);
namen.lines++;
}
else
{
zeile[j] = str[i];
j++;
}
i++;
}
}
VOID open_multidisk(VOID)
{
UBYTE s[256];
UBYTE m2_error_str[80];
PATH name;
WORD icon, icon_x, icon_y, i;
LONG y;
RECT win;
BOOLEAN no_text, no_prj, weiter, do_goto;
BOOLEAN text, open;
BOOLEAN is_projekt;
/* dump_namen();*/
no_prj = no_text = FALSE;
weiter = next_cmd(s,TRUE);
while (weiter && (!abbruch() || note(2,BREAK)==2))
{
text = TRUE;
open = TRUE;
m2_error_str[0] = EOS;
desire_x = 0;
desire_y = 0;
do_goto = FALSE;
icon_x = icon_y = win.x = win.y = win.w = win.h = -1;
strcpy(name ,s);
is_projekt = filematch(name, "*.QPJ");
if (is_projekt)
text = FALSE;
weiter = next_cmd(s,TRUE); /* nächstes Token */
if (weiter && *s >= '0' && *s <= '9') /* Zeilennummer übergeben */
{
do_goto = TRUE;
y = atol(s) - 1;
if (y > 0)
desire_y = y;
weiter = next_cmd(s,TRUE); /* nächstes Token */
if (weiter && *s >='0' && *s <= '9') /* auch Zahl => x-Position */
{
i = atoi(s) - 1;
if (i > 0)
desire_x = i;
weiter = next_cmd(s,TRUE); /* nächstes Token */
}
}
while (weiter && *s=='-')
{
switch(s[1])
{
case 'o':
open = FALSE; /* -o : nicht öffnen */
break;
case 't':
if (is_projekt)
text = TRUE; /* -t : Projekt als Text laden */
break;
case 'i':
if (!next_cmd(s,TRUE))
return; /* -i Icon-Position */
icon_x = atoi(s);
if (!next_cmd(s,TRUE))
return;
icon_y = atoi(s);
break;
case 'w':
if (!next_cmd(s,TRUE))
return; /* -w Fensterkoordinaten */
win.x = atoi(s);
if (!next_cmd(s,TRUE))
return;
win.y = atoi(s);
if (!next_cmd(s,TRUE))
return;
win.w = atoi(s);
if (!next_cmd(s,TRUE))
return;
win.h = atoi(s);
break;
}
weiter = next_cmd(s,TRUE); /* nächstes Token */
}
if (weiter && s[0]=='"' && s[strlen(s)-1]=='"') /* Fehlertext des M2-Compilers */
{
*(UBYTE*)COPYB(m2_error_str,s,78) = EOS;
weiter = next_cmd(s,TRUE); /* nächstes Token */
}
icon = -1;
if (name[strlen(name)-1]=='\\') /* Es wurde Pfad übergeben */
{
set_fsel_path(name);
do_icon(idisk, DO_OPEN);
continue; /* nicht weiter */
}
if (text && !no_text && (name[0] != EOS))
{
if (!caseSens(name, NULL))
str_upper(name);
if ((icon=still_loaded(name))<0)
{
icon = load_edit (name, FALSE, icon_x, icon_y, &win);
if (icon < -1)
no_text = TRUE; /* Keine Texte mehr laden */
}
}
else if (!text && !no_prj && (name[0] != EOS))
{
if (!caseSens(name, NULL))
str_upper(name);
if ((icon=prj_still_loaded(name))<0)
{
icon = load_projekt (name, FALSE, icon_x, icon_y, &win);
if (icon < -1)
no_prj = TRUE; /* Kein Projekt mehr laden */
}
}
if (icon >= 0)
{
if (m2_error_str[0] != EOS)
{
strcpy(s, STRING(ERRORSTR));
strcat(s, m2_error_str);
set_info(get_text(icon), s);
}
if (open && !(nkc_kstate() & 3L))
do_icon(icon, DO_OPEN);
}
if (do_goto) /* Zeilennummer übergeben */
Icon_edit(icon, DO_GOTO);
}
}
/*****************************************************************************/
VOID init_disk (VOID)
{
strcpy(fsel.suffix,"*.*");
fsel.name[0] = EOS;
di_nr = get_first_drive();
disk_type = decl_icon_type(icon_test,icon_edit,icon_exist,icon_drag);
}